<template>
	<view>
		<view
			v-if="!loading && list.length > 0"
		>
			<List
				class="mar-b-10"
				v-for="(item, index) in list"
				:key="index"
				:id="item.RepairTaskId"
				:state="state"
				:orderNo="item.RepairTaskNum"
				:dates="item.CreateDate"
				:customerName="item.Customer.CName"
				:currentRow="item"
				@handleItemClick="handleItemClick"
			/>
		</view>
		
		<view v-if="list.length > 0" class="flex justify-center mar-t-40 color-999999">
			<text>~ 没有更多数据了</text>
		</view>
		
		<!-- 页面加载 -->
		<u-loading-page :loading="loading" loadingText="加载中..." fontSize="16px"></u-loading-page>
		
		<!-- 空数据 -->
		<u-empty
			v-if="list.length === 0 && !loading" mode="data"
			text="~暂无数据"
			icon="http://cdn.uviewui.com/uview/empty/data.png"
		></u-empty>
	</view>
</template>

<script>
	import List from '@/components/Repair/List/index'
	
	import { mapState } from 'vuex'
	import { checkLogin } from '@/utils/lib'
	import { getList } from '@/apis/dispatchWorkManage/index'
	
	export default {
		components: {
			List,
		},
		
		computed: {
			...mapState({
				token: state => state.user.token,
				longitude: state => state.user.longitude,
				latitude: state => state.user.latitude,
				textMsgList: state => state.repair.textMsgList,
				pictureList: state => state.repair.pictureList,
				voiceList: state => state.repair.voiceList,
				videoList: state => state.repair.videoList,
				repairList: state => state.repair.repairList
			})
		},
		
		data() {
			return {
				// 标签状态：0 未派工，1 待接收，2 已退回，3 已派工
				// 这个和后台接口的状态不一致，需要自行判断，因为后台接口给的状态有点乱
				state: 2,
				
				// 加载
				loading: false,
				
				// 列表数据
				list: []
			}
		},
		
		onLoad() {},
		
		onShow() {
			checkLogin()
			this.findList()
		},
		
		methods: {
			// 查询列表
			findList() {
				this.loading = true
				let params = {
					taskType: 1,
					state: 3,
					token: this.token,
					location: this.longitude + ',' + this.latitude
				}
				
				getList(params).then(res => {
					this.loading = false
					this.list = res.Result
					uni.setNavigationBarTitle({
						title: `已退回` + (this.list.length > 0 ? `(${this.list.length})` : '')
					})
				}).catch(err => {
					this.loading = false
				})
			},
			
			// 跳转到详情页
			handleItemClick(row) {
				uni.navigateTo({
					url: `/pages/dispatchWorkManage/details/details?state=${ this.state }&RepairTaskId=${ row.RepairTaskId }&RepairOrderId=${ row.RepairOrderId }`
				})
			},
		}
	}
</script>

<style>

</style>
